home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / rng / default.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-17  |  2.3 KB  |  92 lines

  1. /* rng/default.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <config.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <gsl/gsl_rng.h>
  25. #include <gsl/gsl_errno.h>
  26.  
  27. /* The initial defaults are defined in the file mt.c, so we can get
  28.    access to the static parts of the default generator. */
  29.  
  30. const gsl_rng_type *
  31. gsl_rng_env_setup (void)
  32. {
  33.   unsigned long int seed = 0;
  34.   const char *p = getenv ("GSL_RNG_TYPE");
  35.  
  36.   if (p)
  37.     {
  38.       const gsl_rng_type **t, **t0 = gsl_rng_types_setup ();
  39.  
  40.       gsl_rng_default = 0;
  41.  
  42.       /* check GSL_RNG_TYPE against the names of all the generators */
  43.  
  44.       for (t = t0; *t != 0; t++)
  45.     {
  46.           if (strcmp (p, (*t)->name) == 0)
  47.             {
  48.               gsl_rng_default = *t;
  49.               break;
  50.             }
  51.     }
  52.  
  53.       if (gsl_rng_default == 0)
  54.     {
  55.       int i = 0;
  56.  
  57.       fprintf (stderr, "GSL_RNG_TYPE=%s not recognized\n", p);
  58.       fprintf (stderr, "Valid generator types are:\n");
  59.  
  60.       for (t = t0; *t != 0; t++)
  61.         {
  62.           fprintf (stderr, " %18s", (*t)->name);
  63.  
  64.           if ((++i) % 4 == 0)
  65.         {
  66.           putchar ('\n');
  67.         }
  68.         }
  69.  
  70.       GSL_ERROR_VAL ("unknown generator", GSL_EINVAL, 0);
  71.     }
  72.  
  73.       fprintf (stderr, "GSL_RNG_TYPE=%s\n", gsl_rng_default->name);
  74.     }
  75.   else
  76.     {
  77.       gsl_rng_default = gsl_rng_mt19937;
  78.     }
  79.  
  80.   p = getenv ("GSL_RNG_SEED");
  81.  
  82.   if (p)
  83.     {
  84.       seed = strtoul (p, 0, 0);
  85.       fprintf (stderr, "GSL_RNG_SEED=%lu\n", seed);
  86.     };
  87.  
  88.   gsl_rng_default_seed = seed;
  89.  
  90.   return gsl_rng_default;
  91. }
  92.